package com.bnz.controller;

import com.bnz.entity.Student;
import com.bnz.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;

@Controller
/*@RequestMapping("/student")*/
public class HelloController {

    @Autowired
    private StudentService studentService;


    @RequestMapping("/hello")
    public String hello(Model model){
        model.addAttribute("username","张三");
        return "welcome";
    }

    //查询所有学生
    @GetMapping("/list")
    public String list(Model model){

        List<Student> studentList=studentService.findAll();

        model.addAttribute("students",studentList);

        return "student/list";
    }

    //查询所有学生
    @GetMapping("/findAll")
    public ModelAndView findAll(){
        List<Student> studentList=studentService.findAll();

        ModelAndView mv=new ModelAndView("student/list","students",studentList);

        return mv;
    }




}
